import React, { Component } from 'react'
import {Switch,Redirect,Route} from "react-router-dom"
export default class RouterView extends Component {
    render() {
        return (
            <Switch>
                {
                    this.props.routers.map((item,index)=>{
                        if(item.type==="route"){
                            return <Route key={index} path={item.path} render={(props)=>{
                                let Com = item.component
                                let Pro = {...this.props,...props}
                                return <Com {...Pro} routers={item.children}></Com>
                            }}></Route>
                        }
                        if(item.type==="redirect"){
                            return <Redirect key={index} from ={item.from} to={item.to}></Redirect>
                        }
                        return null
                    })
                }
            </Switch>
        )
    }
}
